let table_name = "user_table";
let table_data_url = "/sys/user/list";
let number_list = "<'row'<'#mytool.col-xs-3'><'col-xs-9'>><'row'<'.col-xs-12'tr>><'row'<'#num_menu.col-xs-2'l><'col-xs-10'p>>";

function action_status() {
}

let dataManage = {
    currentItem: null,
    fuzzySearch: true,
    getQueryCondition: function (data) {
        let param = {};
        param.nickName = $('#nick_name').val();
        param.telephone = $('#telephone').val();
        param.type = 0;
        param.start = data.start;
        param.length = data.length;
        return JSON.stringify(param);
    },
};

let returnData = {
    getDate: [
        {
            className: "ellipsis",
            data: "",
            render: CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
            orderable: false,
            width: "50px"
        }, {
            className: "ellipsis",
            data: "phone",
            render: CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
            orderable: false,
            width: "50px"
        },
        {
            className: "ellipsis",
            data: "img",
            orderable: false,
            width: "50px",
            render: function (data, type, row, meta) {
                if (isNotNull(row.img)) {
                    return '<img alt="" src="http://img.shengongying.cn/' + row.img + '" width="50px" height="50px">';
                }
            }
        }, {
            className: "ellipsis",
            data: "nickName",
            render: CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
            orderable: false,
            width: "50px"
        }, {
            className: "ellipsis",
            data: "sex",
            orderable: false,
            width: "50px",
            render: function (data, type, row, meta) {
                if (row.sex === 0) {
                    return '男';
                } else if (row.sex === 1) {
                    return '女';
                } else {
                    return '未知';
                }
            }
        }, {
            className: "ellipsis",
            data: "birthday",
            render: CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
            orderable: false,
            width: "50px",
            render: function (data, type, row, meta) {
                if (isNotNull(row.birthday)) {
                    return DateUtils.formatterDateNoTime(new Date(row.birthday));
                }
            }
        }, {
            className: "ellipsis",
            data: "signature",
            render: CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
            orderable: false,
            width: "50px"
        }, {
            className: "ellipsis",
            data: "address",
            render: CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
            orderable: false,
            width: "50px"
        },
        {
            className: "ellipsis",
            data: "",
            orderable: false,
            width: "50px",
            render: function (data, type, row, meta) {
                let button = '';
                if (row.status === 2) {
                    button += '<button class="btn btn-sm btn-danger" onclick=update_status(' + row.id + ',0)>解除禁言</button>'
                } else {
                    button += '<button class="btn btn-sm btn-danger" onclick=update_user_disable(' + row.id + ')>禁言</button>';
                }
                button += '<button class="btn btn-sm btn-success" onclick=send_official(' + row.id + ')>发送官方消息</button><button class="btn btn-sm btn-info" onclick=see_resume_info(' + row.id + ')>查看简历</button>';
                button += '<button class="btn btn-sm btn-danger" onclick=delete_user(' + row.id + ')>删除用户</button>';
                return button;
            }
        }
    ]
}

function foot_info(result) {
}

function createdRow(row, data, index) {
    if (data.role) {
        $(row).addClass("info");
    }
}

function drawCallback(settings) {
}

function search_user() {
    find();
}

function fn_draw_call_back() {
}

function update_status(userId, type) {
    HttpUtils.post_json('/sys/user/update/status', JSON.stringify({
        'id': userId,
        'status': type,
    }), function (result) {
        success_msg("更新成功", function () {
            $('#change_user_member_status_modal').modal('hide');
            find();
        });
    });
}

function update_user_disable(id) {
    $('#_user_member_id').val(id);
    $('#disable_user_msg_modal').modal('show');
}

modalClose('disable_user_msg_modal', function () {
    $('#_user_member_id').val('');
});

function update_user_disable_time() {
    let day = $('#disable_day option:selected').val();
    let userId = $('#_user_member_id').val();
    HttpUtils.post_json('/sys/user/update/disable/time', JSON.stringify({
        "id":userId,
        "day": day
    }), function (res) {
        success_msg("成功", function () {
            $('#disable_user_msg_modal').modal('hide');
            find();
        });
    });
}


function send_official(userId) {
    $('#user_member_id').val(userId);
    $('#send_official_msg_modal').modal('show')
}

modalClose('send_official_msg_modal', function () {
    $('#user_member_id').val('');
    $('#msg').val('');
});

function send_to_user() {
    let userId = $('#user_member_id').val();
    let msg = $('#msg').val();
    if (isNull(msg)) {
        wrong_msg("请填写消息");
        return false;
    }
    HttpUtils.post_json('/sys/user/official/msg', JSON.stringify({
        'id': userId,
        'msg': msg
    }), function (result) {
        success_msg("发送成功", function () {
            $('#send_official_msg_modal').modal('hide');
            find();
        });
    });
}


function see_resume_info(userId) {
    window.location.href = '/sys/user/worker/list/index?userId=' + userId;
}

function delete_user(id) {
    HttpUtils.post_json("/sys/user/delete", JSON.stringify({"id": id}), function (result) {
        success_msg("删除成功", function () {
            find();
        });
    });
}